<template>
	<view>
		<Login :utype="utype" :redirect="redirect" :single_login="single_login" @afterLogin="redirectTo"
			@handleChangeLogin="handleChangeLogin"></Login>
	</view>
</template>

<script>
	import Login from '@/components/Login'
	export default {
		name: 'MemberLogin',
		components: {
			Login
		},
		data() {
			return {
				redirect: '',
				utype: 2,
				after_login_data: {},
				single_login: false,
				utype_alias: ''
			}
		},
		onLoad(options) {
			if (options.utype_alias) {
				this.utype = options.utype_alias === 'company' ? 1 : 2
			}
			if (options.after_login_data) {
				var url = options.redirect !== undefined ? decodeURIComponent(options.redirect) : ''
				this.redirect = url + '?id=' + options.id + '&method=' + options.after_login_data
				this.after_login_data.method = options.after_login_data
				this.single_login = options.single_login !== undefined ? options.single_login : false
			}
		},
		methods: {
			redirectTo() {
				var that = this
				if (this.redirect !== '') {
					uni.redirectTo({
						url: this.redirect,
					})
				} else {
					if (this.utype === 1) {
						uni.redirectTo({
							url: '/company/CompanyIndex'
						})
					} else {
						uni.redirectTo({
							url: '/personal/PersonalIndex'
						})
					}
				}
			},
			handleChangeLogin(data) {
				this.utype = data.query.utype_alias === 'company' ? 1 : 2
				this.redirect = data.redirect !== undefined ? options.redirect : ''
			}
		}
	}
</script>